package test.enba.ex.controller;

import com.enba.boot.core.exception.AuthException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import test.enba.ex.param.TestParam;

@RestController
@RequestMapping("/ex")
public class ExController {

  @GetMapping("/throw-runEx")
  public String throwRuntimeException() {
    throw new RuntimeException("测试抛出运行时异常");
  }

  @GetMapping("/throw2")
  public String throwRuntimeException2(@RequestParam String name) {
    return "参数捕获参数异常";
  }

  @GetMapping("/throwAuthException")
  public String throwAuthException() {
    AuthException.throwEx();
    return "测试抛出捕获自定义异常";
  }

  @PostMapping("/methodArgumentNotValidException")
  public String methodArgumentNotValidException(@RequestBody @Validated TestParam param) {
    System.out.println(param);
    return "测试抛出MethodArgumentNotValidException异常";
  }
}
